!function (t) {
    function i(s) {
        if (e[s]) return e[s].exports;
        var n = e[s] = {
            exports: {},
            id: s,
            loaded: !1
        };
        return t[s].call(n.exports, n, n.exports, i), n.loaded = !0, n.exports
    }
    var e = {};
    return i.m = t, i.c = e, i.p = "./", i(0)
}([function (t, i, e) {
    e(1),e(2)
},  function (t, i) {
    Vue.component("pop-agent-commission-set-component", {
        template:'<div class="pop-panel" v-bind:class="{\'show\':this.show}"><div class="pop-box"><div class="pop-title">{{title}}<a class="win_close_btn" @click="close()"><i class="fa fa-fw fa-close"></i></a></div><div class="pop-content"><div class="row"><div class="col-xs-12"><h2 class="page-header" style="font-size:16px;margin:0px 0 20px 0;padding-bottom:10px;overflow:hidden;">名称：{{agent.name}}<small class="pull-right">上次设置时间: {{last_update_time}}</small></h2></div></div><div class="row"><div class="col-xs-12 table-responsive"><validator name="validatorMethod"><form role="form"><table class="table table-striped"><thead><tr><th>商品名称</th><th>已生效佣金</th><th>未生效佣金</th><th>新佣金设置</th></tr></thead><tbody><tr  v-for="item in agentCommissionSet"><td>{{item.name}}</td><td><span style="color: #ff470e">{{item.commission_ratio}}%</span></td><td><template v-if="item.is_take_effect==0" >{{item.new_commission_ratio}}% -- <span style="color: #ff470e">生效时间：{{item.take_effect_time}}</span></template><template v-if="item.is_take_effect==1" >--</template></td><td><input type="text" @invalid="commissionInvalid" detect-change="off" detect-blur="off" initial="off" v-validate:commission="[\'required\']" v-bind:value="item.value" v-model="item.value" class="NumDecText" style="text-align:center;width:80px;">%</td></tr></tbody></table><div class="box-footer"><button type="button" class="btn btn-info btn-sm" style="width:120px;float:left;" @click="save()">保存</button><button type="button" class="btn  btn-default btn-sm" style="width:120px;float:left;margin-left:15px;" @click="close()">取消</button><span style="float:left;color:red;margin-left:15px;line-height"30px>注：佣金修改后，下个交易日生效</span></div></form></validator></div></div></div></div><div class="overlay hidden" id="load_comp"><i class="fa fa-refresh fa-spin"></i></div><div class="bg"></div></div>',
        data: function () {
            return {
                show: !1,
                title:'提示窗口',
                showError:null,
                agent:null,
                last_update_time:'--',
                agentCommissionSet:null
            }
        },
        events: {
            'openAgentCommissionSetWin': function (t) {
                $(".NumDecText").keyup(function(){
                    $(this).val($(this).val().replace(/[^0-9.]/g,''));
                }).bind("paste",function(){  //CTR+V事件处理
                    $(this).val($(this).val().replace(/[^0-9.]/g,''));
                }).css("ime-mode", "disabled"); //CSS设置输入法不可用
                var i = this;
                i.data_init(t);
            },
        },
        methods: {
            commissionInvalid:function () {
                var t = this;
                t.showError.push("佣金设置不能为空");
            },
            data_init: function (t) {
                this.title = t.title, this.agent = t.agent, this.getDate();
            },
            getDate: function () {
                var t = this;
                showLoad();
                postMsg(root+"/agent/getAgentCommissionSet", {agent_id:t.agent.id}, function(i) {
                    hideLoad();
                    t.agentCommissionSet = i.agentCommissionSet;
                    t.last_update_time = i.last_update_time;
                    hideLoadById("#load_comp");
                    t.show = !0;
                });
            },
            save: function() {
                var t = this;
                t.$validate(true,function () {
                    if(!t.$validatorMethod.invalid) {
                        var sub_p = new Object();
                        sub_p.agent_id = t.agent.id;
                        var arr = [];
                        for (var i=0; i<t.agentCommissionSet.length; i++) {
                            var agentCommissionSet = new Object();
                            agentCommissionSet.id = t.agentCommissionSet[i].id;
                            agentCommissionSet.value = t.agentCommissionSet[i].value;
                            agentCommissionSet.game_name = t.agentCommissionSet[i].name;
                            agentCommissionSet.game_type = t.agentCommissionSet[i].type;
                            agentCommissionSet.open_time = t.agentCommissionSet[i].open_time;
                            arr.push(agentCommissionSet);
                        }
                        sub_p.agentCommissionSet = arr;
                        postMsg(root+"/agent/addAgentCommissionSet", sub_p, function(i) {
                            layer.alert(i.msg, {end:function () {
                                if (i.code == 0) {
                                    t.show = !1;
                                }
                            }});
                        });
                    } else {
                        layer.alert(t.showError[(t.showError.length-1)], {end:function () {
                            t.showError = [];
                        }});
                    }
                });
            },
            close: function () {
                var t = this;
                t.show = !1;
            }
        }
    })
},  function (t, i) {
    Vue.component("pop-tree-organization-component", {
        template:'<div class="pop-panel" v-bind:class="{\'show\':this.show}"><div class="pop-box" style="width: 275px;"><div class="pop-title">{{title}}<a class="win_close_btn" @click="close()"><i class="fa fa-fw fa-close"></i></a></div><div class="pop-content"><div style="height:250px;width:100%;overflow-y:scroll;overflow-x:auto;"><ul id="treeDemo" class="ztree"></ul></div><div class="box-footer"><button type="button" class="btn btn-info btn-sm" @click="selectOrg()" style="width:120px;float:left;" v-bind:disabled="isDisabled">{{button}}</button><button type="button" class="btn  btn-default btn-sm" style="width:120px;float:left;margin-left:15px;" @click="close()">取消</button></div></div></div><div class="bg"></div></div>',
        data: function () {
            return {
                show: !1,
                title:'经纪人归属',
                button:'确认选择',
                selectNode:null,
                oldNode:null,
                agent:null,
                isDisabled:0,
            }
        },
        events: {
            'openTreeOrganizationWin': function (t) {
                var i = this;
                i.data_init(t);
            },
        },
        methods: {
            data_init: function (t) {
                this.selectNodes=[],this.agent=t.agent;
                this.getTree();
            },
            getTree:function () {
                var t = this;
                postMsg(root+"/organization/tree2", {agent_id:t.agent.id}, function(i) {
                    var setting = {
                        callback:{
                            beforeClick: function (treeId, treeNode) {
                                return (treeNode.isP === 1);
                            },
                            onClick:function (event, treeId, treeNode, clickFlag) {
                                if (clickFlag == 1) {
                                    t.selectNode = treeNode;
                                    t.isDisabled = !1;
                                } else {
                                    t.selectNode = null;
                                    t.isDisabled = 0;
                                }
                            }
                        }
                    };
                    var treeObj = $.fn.zTree.init($("#treeDemo"), setting, i);
                    var nodes = treeObj.getNodes();
                    t.ergodicTree(nodes, treeObj);
                });
            },
            ergodicTree:function (nodes, treeObj) {
                if (nodes.length>0) {
                    for (var i = 0; i<nodes.length; i++) {
                        if (nodes[i].selected == true) {
                            treeObj.selectNode(nodes[i]);
                            this.oldNode = nodes[i];
                            treeObj.setting.callback.onClick(null, treeObj.setting.treeId, nodes[i], true);//触发函数
                        }
                        if (nodes[i].children !== undefined) {
                            this.ergodicTree(nodes[i].children, treeObj);
                        }
                    }
                }
                this.show = !0;
            },
            selectOrg:function () {
                var t = this;
                if (t.selectNode == null) {
                    layer.alert('请选择一个机构');
                } else {
                    if(t.oldNode != null && t.oldNode.id == t.selectNode.id) {
                        t.close();
                    } else {
                        layer.confirm('确定要将该经纪人移动到“'+t.selectNode.name+'”下吗？', {
                            btn: ['确定','取消'] //按钮
                            ,closeBtn: 0
                        }, function(index){
                            layer.close(index);
                            var org_level = t.selectNode.org_level;
                            var org_id = t.selectNode.id;
                            var agent_id = t.agent.id;
                            postMsg(root+"/agent/changeBelong", {org_level:org_level, org_id:org_id, agent_id:agent_id}, function(i) {
                                if (i.code == 1) {
                                    layer.alert("经纪人归属已转换", {end:function () {
                                        t.agent.micro_ring = t.selectNode.name;
                                        t.close();
                                    }});
                                } else {
                                    layer.alert("经纪人归属转换失败");
                                }
                            });

                        });
                    }
                }
            },
            close: function () {
                var t = this;
                t.show = !1;
                t.isDisabled = 0;
                t.selectNode = null;
                t.oldNode=null;
                t.agent=null;
            }
        }
    })
}]);